1   /*
2    * Copyright (C) 2007 The Guava Authors
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.google.common.collect.testing;
18  
19  import com.google.common.annotations.GwtCompatible;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import java.util.ListIterator;
24  
25  /**
26   * A utility similar to {@link IteratorTester} for testing a
27   * {@link ListIterator} against a known good reference implementation. As with
28   * {@code IteratorTester}, a concrete subclass must provide target iterators on
29   * demand. It also requires three additional constructor parameters:
30   * {@code elementsToInsert}, the elements to be passed to {@code set()} and
31   * {@code add()} calls; {@code features}, the features supported by the
32   * iterator; and {@code expectedElements}, the elements the iterator should
33   * return in order.
34   * <p>
35   * The items in {@code elementsToInsert} will be repeated if {@code steps} is
36   * larger than the number of provided elements.
37   *
38   * @author Chris Povirk
39   */
40  @GwtCompatible
41  public abstract class ListIteratorTester<E> extends
42      AbstractIteratorTester<E, ListIterator<E>> {
43    protected ListIteratorTester(int steps, Iterable<E> elementsToInsert,
44        Iterable<? extends IteratorFeature> features,
45        Iterable<E> expectedElements, int startIndex) {
46      super(steps, elementsToInsert, features, expectedElements,
47          KnownOrder.KNOWN_ORDER, startIndex);
48    }
49  
50    @Override
51    protected final Iterable<? extends Stimulus<E, ? super ListIterator<E>>>
52        getStimulusValues() {
53      List<Stimulus<E, ? super ListIterator<E>>> list =
54          new ArrayList<Stimulus<E, ? super ListIterator<E>>>();
55      Helpers.addAll(list, iteratorStimuli());
56      Helpers.addAll(list, listIteratorStimuli());
57      return list;
58    }
59  
60    @Override protected abstract ListIterator<E> newTargetIterator();
61  }